Skip to content

Add cancellation-aware async selectors#354

Merged
thomhurst merged 2 commits into
mainfrom
issue-336-cancellation-aware-selectors
Jul 21, 2026
Merged

Add cancellation-aware async selectors#354
thomhurst merged 2 commits into
mainfrom
issue-336-cancellation-aware-selectors

Conversation

@thomhurst

Copy link
Copy Markdown
Owner

Summary

  • add CancellationToken-aware SelectAsync and ForEachAsync overloads for enumerable, async-enumerable, item, and execution-count builders
  • adapt each selector once to the builder's linked processor token, preserving existing wrapper and tokenless paths
  • verify in-flight work is interrupted by CancelAll, DisposeAsync, and external cancellation

Validation

  • full solution restore/build succeeds
  • 1,626 tests pass across net8.0, net9.0, and net10.0
  • compiled API inspection confirms token-aware and tokenless overloads coexist

Closes #336

@greptile-apps

greptile-apps Bot commented Jul 21, 2026

Copy link
Copy Markdown

Greptile Summary

This PR adds cancellation-aware async selectors across the processor APIs. The main changes are:

  • New token-aware SelectAsync and ForEachAsync overloads.
  • Linked processor tokens passed to selector callbacks.
  • Cleanup waits for in-flight async-enumerable selectors.
  • Tests for cancellation through CancelAll, disposal, and external tokens.

Confidence Score: 5/5

This looks safe to merge.

  • The updated unbounded processors wait for started selectors during cancellation.
  • The result path preserves the exception already leaving enumeration.
  • Tests confirm execution stays active until delayed selector cleanup completes.
  • No blocking issue remains in the changed code.

Important Files Changed

Filename Overview
EnumerableAsyncProcessor/RunnableProcessors/AsyncEnumerable/AsyncEnumerableParallelProcessor.cs Waits for all started action tasks when unbounded enumeration exits.
EnumerableAsyncProcessor/RunnableProcessors/AsyncEnumerable/ResultProcessors/ResultAsyncEnumerableParallelProcessor.cs Waits for result-selector cleanup while preserving the exception already leaving enumeration.
EnumerableAsyncProcessor.UnitTests/CancellationAwareSelectorTests.cs Covers processor, disposal, and external cancellation of in-flight selectors.
EnumerableAsyncProcessor/Builders/AsyncEnumerableActionAsyncProcessorBuilder_1.cs Adapts token-aware action selectors to the linked processor token.
EnumerableAsyncProcessor/Builders/AsyncEnumerableActionAsyncProcessorBuilder_2.cs Adapts token-aware result selectors to the linked processor token.

Reviews (2): Last reviewed commit: "fix: await async selector cleanup" | Re-trigger Greptile

Add token-aware SelectAsync and ForEachAsync overloads for enumerable, async-enumerable, item, and execution-count builders. Adapt each delegate once to the builder's linked processor token so CancelAll, disposal, and external cancellation interrupt in-flight work without changing tokenless paths.
External cancellation can end source enumeration before started selectors finish. Keep unbounded action and result execution alive through selector cleanup.

Refs #336
@thomhurst
thomhurst force-pushed the issue-336-cancellation-aware-selectors branch from 3ca0ada to 03785b4 Compare July 21, 2026 19:31
@thomhurst
thomhurst merged commit 1089f68 into main Jul 21, 2026
7 checks passed
@thomhurst
thomhurst deleted the issue-336-cancellation-aware-selectors branch July 21, 2026 19:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add CancellationToken-aware selector overloads so in-flight work is cancellable

1 participant